
DEFINE INPUT PARAMETER email AS CHARACTER .
DEFINE INPUT PARAMETER fsubj AS CHARACTER .
DEFINE INPUT PARAMETER fpath AS CHARACTER .
DEFINE INPUT PARAMETER fname AS CHARACTER .
DEFINE INPUT PARAMETER frmks AS CHARACTER .

DEFINE VARIABLE hSession AS INTEGER.

DEFINE VARIABLE ret AS INTEGER. 

DEFINE VARIABLE MapiMessage AS MEMPTR.

DEFINE VARIABLE  lpszSubject AS MEMPTR.
DEFINE VARIABLE  lpszNoteText AS MEMPTR.
DEFINE VARIABLE  lpszMessageType AS MEMPTR.
DEFINE VARIABLE  lpszDateReceived AS MEMPTR.
DEFINE VARIABLE  lpszConversationID AS MEMPTR.
DEFINE VARIABLE  lpOriginator AS MEMPTR.
DEFINE VARIABLE  lpRecips AS MEMPTR.
DEFINE VARIABLE  lpFiles AS MEMPTR.

DEFINE VARIABLE  lpszName AS MEMPTR.
DEFINE VARIABLE  lpszAddress AS MEMPTR.

DEFINE VARIABLE  lpszFileName AS MEMPTR.
DEFINE VARIABLE  lpszFilePath AS MEMPTR.
/*
DEFINE VARIABLE email AS CHARACTER.

email = "fdn@huntkey.net" .
*/

RUN MAPILogon( INPUT 0, INPUT "", INPUT "", INPUT 1, INPUT 0, OUTPUT hSession, OUTPUT ret ).
 

SET-SIZE(MapiMessage) = 48 .

PUT-LONG(MapiMessage,1) = 0 .   /*ulReserved*/

SET-SIZE(lpszSubject) = 64.
PUT-STRING(lpszSubject, 1) = fsubj.
PUT-LONG(MapiMessage,5) = GET-POINTER-VALUE(lpszSubject).

SET-SIZE(lpszNoteText) = 64.
PUT-STRING(lpszNoteText, 1) = frmks.
PUT-LONG(MapiMessage,9) = GET-POINTER-VALUE(lpszNoteText).

/*
SET-SIZE(lpszMessageType) = 64.
PUT-STRING(lpszMessageType, 1) = "".
*/
PUT-LONG(MapiMessage,13) = 0. /* GET-POINTER-VALUE(lpszMessageType).*/
 
SET-SIZE(lpszDateReceived) = 64.
PUT-STRING(lpszDateReceived, 1) = "".
PUT-LONG(MapiMessage,17) = GET-POINTER-VALUE(lpszDateReceived).
 
SET-SIZE(lpszConversationID) = 64.
PUT-STRING(lpszConversationID, 1) = "".
PUT-LONG(MapiMessage,21) = GET-POINTER-VALUE(lpszConversationID).

PUT-LONG(MapiMessage,25) = 4.   /* flFlags = MAPI_SENT*/

PUT-LONG(MapiMessage,29) = 0. /* GET-POINTER-VALUE(lpOriginator). */

PUT-LONG(MapiMessage,33) = 1. /* RecipCount */

SET-SIZE(lpRecips) = 24.

PUT-LONG(lpRecips, 5) = 1.   /* ulRecipClass; MAPI_TO = 1 */
SET-SIZE(lpszName) = 64.
PUT-STRING(lpszName, 1, 64) = email .

PUT-LONG(lpRecips, 9) = GET-POINTER-VALUE(lpszName).
SET-SIZE(lpszAddress) = 64.
PUT-LONG(lpRecips,13) = GET-POINTER-VALUE(lpszAddress).

PUT-LONG(MapiMessage,37) = GET-POINTER-VALUE(lpRecips). /* MapiRecipDesc */

IF fpath = "" THEN
    PUT-LONG(MapiMessage,41) = 0. /*FileCount*/
ELSE
    PUT-LONG(MapiMessage,41) = 1. /*FileCount*/


SET-SIZE(lpFiles) = 24.

PUT-LONG(lpFiles, 1) = 0.
PUT-LONG(lpFiles, 5) = 0.
PUT-LONG(lpFiles, 9) = -1.

SET-SIZE(lpszFilePath) = 64.
PUT-STRING(lpszFilePath,1) = fpath .
PUT-LONG(lpFiles,13) = GET-POINTER-VALUE(lpszFilePath).

SET-SIZE(lpszFileName) = 64.
PUT-STRING(lpszFileName,1) = fname.
PUT-LONG(lpFiles,17) = GET-POINTER-VALUE(lpszFileName).

PUT-LONG(lpFiles, 21) = 0.

PUT-LONG(MapiMessage,45) = GET-POINTER-VALUE(lpFiles).

RUN MAPIResolveName( INPUT hSession, INPUT 0, INPUT email, INPUT 0, INPUT 0,OUTPUT lpRecips , OUTPUT ret) NO-ERROR.

PUT-LONG(lpRecips,5) = 1.   /* ulRecipClass; MAPI_TO = 1 */

RUN MAPISendMail(INPUT hSession, INPUT 0, INPUT-OUTPUT MapiMessage, INPUT 0, INPUT 0, OUTPUT ret) NO-ERROR .

RUN MAPILogoff(INPUT hSession, INPUT 0, INPUT 0, INPUT 0, OUTPUT ret) NO-ERROR.

RUN MAPIFreeBuffer(INPUT lpRecips, OUTPUT ret) NO-ERROR.

PROCEDURE MAPILogon EXTERNAL "mapi32.dll" :
     
    DEFINE INPUT PARAMETER  ulUIParam AS LONG.
    DEFINE INPUT PARAMETER  lpszProfileName AS CHARACTER.
    DEFINE INPUT PARAMETER  lpszPassword AS CHARACTER.
    DEFINE INPUT PARAMETER  flFlags AS LONG.
    DEFINE INPUT PARAMETER  ulReserved AS LONG.
    DEFINE OUTPUT PARAMETER lplhSession AS LONG.
    DEFINE RETURN PARAMETER retVal AS LONG.

END.

PROCEDURE MAPIResolveName EXTERNAL "mapi32.dll" :

    DEFINE INPUT PARAMETER  lhSession AS LONG.
    DEFINE INPUT PARAMETER  ulUIParam AS LONG.
    DEFINE INPUT PARAMETER  lpszName AS CHARACTER.
    DEFINE INPUT PARAMETER  ulFlags AS LONG.
    DEFINE INPUT PARAMETER  ulReserved AS LONG.
    DEFINE OUTPUT PARAMETER lppRecip AS MEMPTR.
    DEFINE RETURN PARAMETER retVal AS LONG.

END.

PROCEDURE MAPISendMail EXTERNAL "mapi32.dll" :

    DEFINE INPUT PARAMETER  lhSession AS LONG.
    DEFINE INPUT PARAMETER  ulUIParam AS LONG.
    DEFINE INPUT-OUTPUT PARAMETER  lpMapiMessage AS MEMPTR.
    DEFINE INPUT PARAMETER  ulFlags AS LONG.
    DEFINE INPUT PARAMETER  ulReserved AS LONG.
    DEFINE RETURN PARAMETER retVal AS LONG.

END.

PROCEDURE MAPILogoff EXTERNAL "mapi32.dll" :
	
    DEFINE INPUT PARAMETER  lhSession AS LONG.
    DEFINE INPUT PARAMETER  ulUIParam AS LONG.
    DEFINE INPUT PARAMETER  ulFlags AS LONG.
    DEFINE INPUT PARAMETER  ulReserved AS LONG.
    DEFINE RETURN PARAMETER retVal AS LONG.
    
END.

PROCEDURE MAPIFreeBuffer EXTERNAL "mapi32.dll" :

	DEFINE INPUT PARAMETER  lpBuffer AS MEMPTR.
	DEFINE RETURN PARAMETER retVal AS LONG.
	
END.
